﻿using System.Collections.Generic;
using System.Web.Mvc;
using xTeam.Glgcx.CommonUtilities;

namespace xTeam.Glgcx.Controllers.Manage
{
    public class ClassifyController : BaseController
    {
        //
        // GET: /Classify/

        public ActionResult Index(string moduleKey = "")
        {
            ViewData["moduleKey"] = moduleKey;
            ViewData.Model = _classifyBal.GetClassiyfListByModuleKey(moduleKey);
            return View("Classify");
        }

        /// <summary>
        /// 获取指定的的分类的详细信息
        /// </summary
        public ActionResult Classify(int classifyId = 0, string moduleKey = "")
        {
            EClassify classify =
                _classifyBal.GetClassifyById(classifyId)
                ?? new EClassify() { ModuleKey = moduleKey };
            List<EClassify> classifyList = _classifyBal.GetClassiyfListByModuleKey(moduleKey);
            ViewData["ClassifyList"] = classifyList;

            #region 探测ModuleKey的有效性

            List<SelectListItem> classifyModuleKey = new List<SelectListItem>();
            classifyModuleKey.Add(new SelectListItem() { Text = "", Value = "" });
            classifyModuleKey.Add(new SelectListItem() { Text = "文 章", Value = "Archive" });
            classifyModuleKey.Add(new SelectListItem() { Text = "系 统", Value = "System" });
            classify.ModuleKey = classifyModuleKey.Exists(i => i.Value.ToUpper() == classify.ModuleKey.ToUpper())
                 ? classify.ModuleKey
                 : string.Empty;
            ViewData["ModuleKey"] = new SelectList(classifyModuleKey, "Value", "Text", classify.ModuleKey);
            this.ModelState.Remove("ModuleKey");
            #endregion


            return View("Post", classify);
        }

        /// <summary>
        /// 保存分类
        /// </summary>
        [HttpPost]
        public ActionResult Save(EClassify classify)
        {
            int result = _classifyBal.Save(classify);

            return new EmptyResult();
        }
        /// <summary>
        /// 删除分类
        /// </summary>
        public ActionResult Delete(int classifyId = 0)
        {
            int result = _classifyBal.Delete(classifyId);
            return new EmptyResult();
        }

    }
}
